<?php
if (!defined('IN_D_ADMIN')) die("Error 404");

if ($level != 1 && $_SESSION['admin_id']!=$conf['super_admin']) {
	echo $lang_acp['u_not_enter'];
	exit();
}
$error_arr = array();
//--------------Config------------------------
$config_arr = array(
	'announcement'	=>
		array(
			'name'	=>	'announcement',
			'desc'	=>	$lang_acp['announcement'],
			'type'	=>	'text',
		),
	'total_visit'	=>
		array(
			'name'	=>	'total_visit',
			'desc'	=>	$lang_acp['total_visit'],
			'type'	=>	'number',
		),
	'web_title'	=>
		array(
			'name'	=>	'web_title',
			'desc'	=>	$lang_acp['web_title'],
			'type'	=>	'free',
		),
	'web_url'	=>
		array(
			'name'	=>	'web_url',
			'desc'	=>	$lang_acp['web_url'],
			'type'	=>	'free',
		),
	'web_email'	=>
		array(
			'name'	=>	'web_email',
			'desc'	=>	$lang_acp['web_email'],
			'type'	=>	'free',
		),
	'download_salt'	=>
		array(
			'name'	=>	'download_salt',
			'desc'	=>	$lang_acp['download_salt'],
			'type'	=>	'free',
		),
	'must_login_to_download'	=>
		array(
			'name'	=>	'must_login_to_download',
			'desc'	=>	$lang_acp['must_login_to_download'],
			'type'	=>	'true_false',
		),
	'must_login_to_play'	=>
		array(
			'name'	=>	'must_login_to_play',
			'desc'	=>	$lang_acp['must_login_to_play'],
			'type'	=>	'true_false',
		),
	'must_login_to_rate'	=>
		array(
			'name'	=>	'must_login_to_rate',
			'desc'	=>	$lang_acp['must_login_to_rate'],
			'type'	=>	'true_false',
		),
	'media_per_page'	=>
		array(
			'name'	=>	'media_per_page',
			'desc'	=>	$lang_acp['media_per_page'],
			'type'	=>	'free',
		),
	'confirm_code'	=>
		array(
			'name'	=>	'confirm_code',
			'desc'	=>	$lang_acp['confirm_code'],
			'type'	=>	'true_false',
		),
	'epi_noajax'	=>
		array(
			'name'	=>	'epi_noajax',
			'desc'	=>	$lang_acp['epi_noajax'],
			'type'	=>	'true_false',
	),
	'root_img'	=>
		array(
			'name'	=>	'root_img',
			'desc'	=>	$lang_acp['root_img'],
			'type'	=>	'free',
		),
	'local_img'	=>
		array(
			'name'	=>	'local_img',
			'desc'	=>	$lang_acp['local_img'],
			'type'	=>	'free',
		),
	'img_thumb'	=>
		array(
			'name'	=>	'img_thumb',
			'desc'	=>	$lang_acp['img_thumb'],
			'type'	=>	'free',
		),
	'album_img'	=>
		array(
			'name'	=>	'album_img',
			'desc'	=>	$lang_acp['dir_album_img'],
			'type'	=>	'free',
		),
	'singer_img'=>
		array(
			'name'	=>	'singer_img',
			'desc'	=>	$lang_acp['dir_singer_img'],
			'type'	=>	'free',
		),
	'album_thumb'=>
		array(
			'name'	=>	'album_thumb',
			'desc'	=>	$lang_acp['dir_album_thumb'],
			'type'	=>	'free',
		),
	'default_lang'	=>
		array(
			'name'	=>	'default_lang',
			'desc'	=>	$lang_acp['default_lang'],
			'type'	=>	'true_false',
			'opt'	=>  'vi#Vietnamese|en#English',
		),
	'dir_imgpl'	=>
		array(
			'name'	=>	'dir_imgpl',
			'desc'	=>	$lang_acp['dir_imgpl'],
			'type'	=>	'free',
	),
	'dir_avatar'	=>
		array(
			'name'	=>	'dir_avatar',
			'desc'	=>	$lang_acp['dir_avatar'],
			'type'	=>	'free',
	),
	'focus_img'	=>
		array(
			'name'	=>	'focus_img',
			'desc'	=>	$lang_acp['dir_focus_img'],
			'type'	=>	'free',
	),
	'focus_thumb'	=>
		array(
			'name'	=>	'focus_thumb',
			'desc'	=>	$lang_acp['dir_focus_thumb'],
			'type'	=>	'free',
	),
	'use_cache_html'	=>
		array(
			'name'	=>	'use_cache_html',
			'desc'	=>	$lang_acp['use_cache_html'],
			'type'	=>	'true_false',
	),
);

if (!empty($_POST['submit'])) {
	$list = array_keys($_POST);
	$ok = true;
	for ($i=0;$i<count($list);$i++) {
		$key = $list[$i];
		$vl = addslashes($_POST[$key]);
		if ($key == 'web_url') 
			if ($vl[strlen($vl)-1] == '/') $vl = substr($vl,0,-1);
		if ($key == 'announcement' && $vl == '<br>') $vl = '';
		if ($key == 'submit') continue;
		if (!array_key_exists($key,$config_arr)) continue;
		if ($config_arr[$key]['type'] == 'number' && (!is_numeric($vl))) { $ok = false; $error_arr[] = $key; }
		if ($ok) $DB->query("UPDATE ".$conf['prefix']."config SET config_value = '".$vl."' WHERE config_name = '".$key."'");
	}
	if ($ok) {
		echo $lang_acp['entered_data']." <meta http-equiv='refresh' content='1;url=$link'>";
		exit();
	}
}

//--------------------------------------------
echo "<form method=post>".
	"<table class=border cellpadding=2 cellspacing=0 width=90%>".
	"<tr><td colspan=2 class=title align=center>Configures</td></tr>";
$q = $DB->query("SELECT * FROM ".$conf['prefix']."config ORDER BY config_name ASC");
while ($r = $DB->fetch_row($q)) {
	if (empty($_POST['submit']) && !count($error_arr)) $vl = stripslashes($r['config_value']);
	else $vl = stripslashes($_POST[$r['config_name']]);
	if (array_key_exists($r['config_name'],$config_arr)) {
		$arr = $config_arr[$r['config_name']];
		if (in_array($r['config_name'],$error_arr)) $symbol = "<font style='color:red'>*</font> ";
		else $symbol = '';
		echo "<tr><td class=fr><b>".$arr['desc']."</b> : </td><td class=fr_2>";
		if (!$arr['type'] || $arr['type'] == 'number' || $arr['type'] == 'free') echo "<input name=".$r['config_name']." size=50 value='".$vl."'>";
		elseif ($arr['type'] == 'text') echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"../js/openwysiwyg/wysiwyg.js\"></script><textarea cols=60 rows=10 id=".$r['config_name']." name=".$r['config_name'].">".$vl."</textarea>"."<script language=\"JavaScript\">generate_wysiwyg('".$r['config_name']."');</script>";
		elseif ($arr['type'] == 'true_false')
			if(!empty($arr['opt'])){
			$opt=explode("|",$arr['opt']);
			$name_opt1=explode("#",$opt[0]);
			$name_opt2=explode("#",$opt[1]);
			echo "<input type=radio name=".$r['config_name']." value={$name_opt1[0]}".(($r['config_value'] == $name_opt1[0])?' checked':'')."> {$name_opt1[1]} <input type=radio name=".$r['config_name']." value={$name_opt2[0]}".(($r['config_value'] == $name_opt2[0])?' checked':'')."> {$name_opt2[1]}";
			}
			else
			echo "<input type=radio name=".$r['config_name']." value=1".(($r['config_value'] == 1)?' checked':'')."> {$lang_acp['true']} <input type=radio name=".$r['config_name']." value=0".(($r['config_value'] == 0)?' checked':'')."> {$lang_acp['false']}";
		if ($arr['type'] == 'number' && in_array($r['config_name'],$error_arr)) echo $lang_acp['must_be_number'];
		echo "</td></tr>";
	}
}
echo "<tr><td colspan=2 align=center><input class=submit name=submit type=submit value=Submit> <input type=reset class=submit value='Reset'></td></tr>";
echo "</table></form>";
?>